﻿#define _CRT_SECURE_NO_WARNINGS/*(编写代码在一个整形有序数组中查找具体的某个数要求：
								 找到了就打印数字所在的下标，找不到则输出：找不到。)*/
#include<stdio.h>
int main()
{
	int b = 0; int left = 0, right = 0, mid = 0;
	int a[] = { 1,2,3,4,5,6,7,8,9 };
	right = (sizeof(a) / sizeof(a[0]));
	/*printf(" %d", right);*/
	printf("请输入要找的数>:");
	scanf("%d", &b);
	while (left <= right)
	{
		mid = (right - left) / 2 + left;
		if (b > a[mid])
			left = mid + 1;
		else if (b < a[mid])
			right = mid - 1;
		else
		{
			printf("找到了，下标为:%d\n", mid);
			break;
		}
	}
	if (left > right)
		printf("找不到");



	return 0;

}